package com.ruoyi.logistic.utils;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

public class TableUtils {

    public static R handleListResponse(List<?> dataList, List<TableVo> fieldList, String emptyMessage) {
        JSONObject responseJson = new JSONObject();
        responseJson.put("list", PageInfo.info(dataList));
        responseJson.put("fields", fieldList);

        if (dataList == null || dataList.isEmpty()) {
            return R.fail(emptyMessage);
        } else {
            return R.ok(responseJson);
        }
    }

    public static R handleObjectResponse(Object object, List<TableVo> fieldList, String emptyMessage) {
        JSONObject responseJson = new JSONObject();
        responseJson.put("list", object);
        responseJson.put("fields", fieldList);

        if (object == null) {
            return R.fail(emptyMessage);
        } else {
            return R.ok(responseJson);
        }
    }
}